package com.lrm.web.admin;

import com.lrm.biz.IUserBiz;
import com.lrm.pojo.User;
import com.lrm.util.Result;
import com.lrm.util.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @Author: 王金海
 * @Description:
 * @Date: Created by Administrator on 2017/11/30.
 * @Modified By:
 */
@RestController
@RequestMapping("admin")
public class LoginController {

    @Autowired
    private IUserBiz userService;

    @GetMapping("/login")
    public Result login(HttpSession session,@RequestParam String username, @RequestParam String password) {
        User user = userService.checkUser(username, password);
        System.out.println(user.getAvatar());
        if (user!= null) {
            user.setPassword("");
            session.setAttribute("user",user);
            return ResultUtil.success(user);
        }
        return ResultUtil.error(2, "用户名或密码错误");
    }

    @GetMapping("listUser")
    public Result listUser() {
        List<User> users = userService.listUser();
        return ResultUtil.success(users);
    }
}
